package ginv

import (
	"context"
	"github.com/gin-gonic/gin"
	"net/http"
)

// 示例请求结构体
type GetPartTimeListReq struct {
	Page     int32 `json:"page" form:"page"`
	PageSize int32 `json:"page_size" form:"page_size"`
}

// 示例响应结构体
type GetPartTimeListRsp struct {
	Ret  int    `json:"ret"`
	Msg  string `json:"msg"`
	Data struct {
		List  []interface{} `json:"list"`
		Total int64         `json:"total"`
	} `json:"data"`
}

// 示例处理函数
func GetPartTimeList(ctx context.Context, req *GetPartTimeListReq, rsp *GetPartTimeListRsp) error {
	// 设置默认值
	if req.Page == 0 {
		req.Page = 1
	}
	if req.PageSize == 0 {
		req.PageSize = 10
	}

	// 模拟业务逻辑
	rsp.Data.List = []interface{}{
		map[string]interface{}{
			"id":    1,
			"title": "兼职工作1",
			"desc":  "这是一个兼职工作描述",
		},
		map[string]interface{}{
			"id":    2,
			"title": "兼职工作2",
			"desc":  "这是另一个兼职工作描述",
		},
	}
	rsp.Data.Total = 2
	rsp.Ret = http.StatusOK
	rsp.Msg = "请求成功"

	return nil
}

// ExampleUsage 展示如何使用链式处理器
func ExampleUsage() {
	// 创建链式处理器并配置路由
	handler := NewChainHandler().
		Use(gin.Logger()).
		Use(gin.Recovery()).
		POST("/api/part-time/list", GetPartTimeList).
		GET("/api/part-time/list", GetPartTimeList)

	// 启动服务器
	handler.Run(":8080")
}
